<template>
  <view>
    <l-background />
    <view class="margin-tb-20">
      <user-info-avatar @update="updateInfo" />

      <user-info-other @update="updateInfo" />

      <user-identity-list v-show="showIdentityList" />
    </view>

    <user-logout />
  </view>
</template>

<script>
import UserInfoAvatar from '../components/user-info-avatar/user-info-avatar'
import UserInfoOther from '../components/user-info-other/user-info-other'
import UserIdentityList from '../components/user-identity-list/user-identity-list'
import UserLogout from '../components/user-logout/user-logout'
import { mapGetters, mapMutations } from 'vuex'
import { updateUserInfo, getUserInfo } from '@/common/api/user'
export default {
  name: 'MyInfo',
  components: {
    UserInfoAvatar,
    UserInfoOther,
    UserIdentityList,
    UserLogout
  },
  data() {
    return {

    }
  },
  computed: {
    showIdentityList() {
      return this.identityList.length > 1
    },
    ...mapGetters({
      identityList: 'identityList'
    })
  },
  methods: {
    // 修改用户信息,手机号和用户名不能通过此接口修改
    async updateInfo(e) {
      const [err, res] = await updateUserInfo(e)
      if (!this.$http.errorCheck(err, res)) return false
      this.toast('修改成功')
      await this.getUserInfo()
    },
    async getUserInfo() {
      const [err, res] = await getUserInfo()
      if (!this.$http.errorCheck(err, res)) return false
      const uerInfo = res.data.data.sysUser
      this.setUserInfo(uerInfo)
    },
    ...mapMutations({
      setUserInfo: 'user/setUserInfo'
    })
  }
}
</script>

<style scoped>

</style>
